package LW.org.serviceImple;

import LW.org.dao.roomDao;
import LW.org.dao.roomUsedao;
import LW.org.dao.userDao;
import LW.org.daoImple.roomUseImple;
import LW.org.model.Room;
import LW.org.model.RoomUse;
import LW.org.service.roomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("roomServiceImple")
public class roomServiceimple implements roomService {

    @Autowired
    @Qualifier("roomDaoImple")
    private roomDao roomdao;
    @Autowired
    @Qualifier("roomUseImple")
    private roomUsedao roomusedao;


    //操作客房信息
    @Override
    public Room find_one(int room_id) {
        Room templateOne = roomdao.select(room_id);
        if (templateOne != null) {
            return templateOne;
        }
        return null;
    }

    @Override
    public List<Room> find_all() {
        List<Room> all = roomdao.select_all();
        if(all!=null&&all.size()>=0)
        {
            return all;
        }
        return null;
    }


    //操作入住、退房信息
    @Override
    public Boolean bookRoom(RoomUse newRoom,int roomId) {

        Boolean status = roomusedao.insert_one_use(newRoom,roomId);
        if(status){
            return true;
        }

        return false;
    }

    @Override
    public Boolean checkOut(int roomId, Boolean roomFlag) {

        try{
            List<RoomUse> find_result = roomusedao.select_key_roomID(roomId,roomFlag);
            RoomUse single = find_result.get(0);
            Boolean updateStatus = roomusedao.update_one(new Date(),single.getHotelInfoId());
            if(updateStatus){
                System.out.println("退房成功！！！");
                return true;
            }
        }catch (Exception e){
            System.out.println("room Service checkOut has error : "+e.toString());
        }
        return false;
    }

    @Override
    public Boolean checkOut(String IDcard, Boolean roomFlag) {
        return null;
    }

    @Override
    public RoomUse find_bookRoom(int roomId, Boolean roomFlag){
        try{
            List<RoomUse> find_result = roomusedao.select_key_roomID(roomId,roomFlag);
            RoomUse single = find_result.get(0);
            if(single!=null){
                return single;
            }
        }catch (Exception e){
            System.out.println("room Service checkOut has error : "+e.toString());
        }
        return null;
    }

    @Override
    public List<RoomUse> return_all_roomUse(){

        List<RoomUse> all = roomusedao.select_all();
        if(all!=null&all.size()>0){
            return all;
        }
        return null;

    }
}
